{% extends "oa/base.html" %}
{% load i18n static %}
{% block title %} 原料库存明细 {% endblock %}
{% block header_nav %}{% endblock %}

{% block content %}
    <section class="panel">
        <div class="panel-body">
            <form method="get" action="{{ request.path }}" class="form-inline">
                <div class="form-group">
                    <label for="id_related_calculate_id">日期:</label>
                    <select name="related_calculate_id" id="id_related_calculate_id" class="form-control">
                        <option value="">-----</option>
                        {% for related_calculate in related_calculates %}
                            {% if related_calculate.pk|escape == request.GET.related_calculate_id|escape %}
                            <option value="{{ related_calculate.pk }}" selected>{{ related_calculate.pk }}-{{ related_calculate.recorded_at }}</option>
                            {% else %}
                            <option value="{{ related_calculate.pk }}">{{ related_calculate.pk }}-{{ related_calculate.recorded_at }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <label for="id_category_id">产品系列:</label>
                    <select name="category_id" id="id_category_id" class="form-control">
                        <option value="">-----</option>
                        {% for category in categories %}
                            {% if category.pk|escape == request.GET.category_id|escape %}
                            <option value="{{ category.pk }}" selected>{{ category.name }}</option>
                            {% else %}
                            <option value="{{ category.pk }}">{{ category.name }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <label for="id_warehouse">仓库:</label>
                    <select name="warehouse" id="id_warehouse" class="form-control">
                        <option value="">-----</option>
                        {% for warehouse in warehouses %}
                            {% if warehouse|escape == request.GET.warehouse|escape %}
                            <option value="{{ warehouse }}" selected>{{ warehouse }}</option>
                            {% else %}
                            <option value="{{ warehouse }}">{{ warehouse }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <div class="form-group">
                    <label for="id_package_unit">包装规格:</label>
                    <select name="package_unit" id="id_package_unit" class="form-control">
                        <option value="">-----</option>
                        {% for package_unit in package_units %}
                            {% if package_unit.pk|escape == request.GET.package_unit|escape %}
                            <option value="{{ package_unit.pk }}" selected>{{ package_unit.display }}</option>
                            {% else %}
                            <option value="{{ package_unit.pk }}">{{ package_unit.display }}</option>
                            {% endif %}
                        {% endfor %}
                    </select>
                </div>
                <button type="submit" class="btn btn-info">重新统计</button>
            <a target="_blank" href="?excel=1&related_calculate_id={{ request.GET.related_calculate_id }}&q={{ request.GET.q }}"><span type="submit" class="btn btn-default">导出EXCEL</span></a>
                </form>
        </div>
    </section>
    <section class="panel">
        <div class="panel-body table-responsive">
            <table class="table table-striped table-bordered">
                <thead>
                    <tr>
                        <th>{% trans '产品' %}</th>
                        <th class="text-center">{% trans '仓库' %}</th>
                        <th class="text-center">{% trans '库存' %}</th>
                        <th class="text-center">{% trans '合计' %}</th>
                        <th class="text-right">{% trans '库存生产成本/元' %}</th>
                        <th class="text-right">{% trans '库存出厂成本/元' %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for row in data_list %}
                    <tr>{% if row.show %}
                        <td rowspan="{{ row.rowspan }}">{{ row.name }}</td>{% endif %}
                        <td class="text-center">{{ row.warehouse }}</td>
                        <td>{{ row.left }} {{ row.unit }}{% ifnotequal row.left row.packs %}({{ row.packs }} {{ row.packs_unit }}）{% endifnotequal %}</td>{% if row.show %}
                        <td rowspan="{{ row.rowspan }}">{{ row.total_b }} {{ row.unit }} {% ifnotequal row.left row.packs %}({{ row.total_p }} {{ row.packs_unit }}）{% endifnotequal %}</td>
                        <td rowspan="{{ row.rowspan }}" class="text-right">{{ row.reference_cost }} x {{ row.total_b }} = {{ row.total_b_p1 }}</td>
                        <td rowspan="{{ row.rowspan }}" class="text-right">{{ row.sales_cost }} x {{ row.total_b }} = {{ row.total_b_p2 }}</td>
                        {% endif %}
                    </tr>
                    {% endfor %}
                    <tr>
                        <td>合计</td>
                        <td colspan="3"></td>
                        <td class="text-right">{{ total_p1 }}</td>
                        <td class="text-right">{{ total_p2 }}</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </section>
{% endblock %}